home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20031118-20041115 / 000333_fdc@columbia.edu_Wed Jul 21 15:58:10 2004.msg < prev    next >
Internet Message Format  |  2020-01-01  |  5KB

  1. Path: newsmaster.cc.columbia.edu!not-for-mail
  2. From: Frank da Cruz <fdc@columbia.edu>
  3. Newsgroups: comp.protocols.kermit.misc
  4. Subject: Transaction processing revisited
  5. Date: 21 Jul 2004 19:29:06 GMT
  6. Organization: Columbia University
  7. Lines: 89
  8. Message-ID: <slrncfth02.t2m.fdc@sesame.cc.columbia.edu>
  9. Reply-To: fdc@columbia.edu
  10. NNTP-Posting-Host: sesame.cc.columbia.edu
  11. X-Trace: newsmaster.cc.columbia.edu 1090438146 14018 128.59.59.56 (21 Jul 2004 19:29:06 GMT)
  12. X-Complaints-To: postmaster@columbia.edu
  13. NNTP-Posting-Date: 21 Jul 2004 19:29:06 GMT
  14. User-Agent: slrn/0.9.8.0 (SunOS)
  15. Xref: newsmaster.cc.columbia.edu comp.protocols.kermit.misc:15085
  16.  
  17. It is an increasingly common question: how to upload a file in such
  18. a way that another process won't try to process it before the upload
  19. is complete?  This sort of operation -- in which a variety of clients
  20. upload transactions (files) to a central service for processing --
  21. is commonly used in EDI applications, insurance claims, etc.  You want
  22. to be sure that each transaction is processed exactly once; not zero,
  23. or two or more times, and that processing takes place only when the
  24. upload is complete and successful.
  25.  
  26. Discussions of transaction processing have been available on the
  27. Kermit website for some time:
  28.  
  29.   http://www.columbia.edu/kermit/case10.html
  30.   http://www.columbia.edu/kermit/ftpscripts.html
  31.  
  32. The second one concerns FTP but the principles are the same -- the
  33. transaction processing example is about halfway down the document, after
  34. the introductory tutorial material.
  35.  
  36. In these documents we talk about uploading files to a temporary working
  37. directory and the moving each file to its final destination only after
  38. the upload is complete and successful.
  39.  
  40. In some situations, however, it is possible that multiple clients might
  41. try to upload different files having the same name to the same working
  42. directory at the same time, and although Kermit's file collision features
  43. can be used to prevent one file from destroying the other, it complicates
  44. the moving or renaming process.
  45.  
  46. Another approach is for the server to ensure that each incoming file has
  47. a unique name.  This way, no collisions will ever take place and no
  48. renaming within the temporary working directory will be necessary.
  49. This can be done with the following command:
  50.  
  51.   set receive rename-to xxx
  52.  
  53. where xxx is a template, as explained here:
  54.  
  55.   http://www.columbia.edu/kermit/ckermit70.html#x4.1
  56.  
  57. Let's say the incoming filename is ABCD1234.FIL, and you want the new name
  58. to incorporate the original name and still have the ".FIL" extension.  Here
  59. are some variables you can use:
  60.  
  61.   \v(filename) = the name the file was sent was (e.g. ABCD1234.FIL).
  62.   \v(ntime)    = current local time, seconds since midnight (e.g. 45369).
  63.   \v(ndate)    = current date, numeric (e.g. 20040716).
  64.   \v(pid)      = Kermit's numeric process ID.
  65.  
  66. The date, time, and PID combined would produce a guaranteed unique filename
  67. because at any given moment, every process (including every Kermit receiver)
  68. has a unique process ID.
  69.  
  70. How to construct the new filename?  Let's assume that the filename contains
  71. only one dot (.).  First use string functions to separate the basename from
  72. the extension:
  73.  
  74.   \fstripx(\v(filename)) = ABCD1234
  75.   \flop(\v(filename))    = FIL
  76.  
  77. Then concatenate with the date, time, and pid; you can use \flpad() to
  78. left-pad variable-length fields (like \v(ntime) or \v(pid)) if you want to
  79. make them fixed-length.  So here is your renaming function:
  80.  
  81.   \fstripx(\v(filename))_\v(ndate)_\flpad(\v(ntime),5,0)_\v(pid).-
  82.   \flop(\v(filename))
  83.  
  84. (This is a single line, which I've broken for benefit of netnews.  Rejoin
  85. by removing the hyphen and the linebreak and indentation.)
  86.  
  87. I've separated the fields with underscores but of course you don't have to
  88. do that, or you can use a different separator.  The command would be:
  89.  
  90.   set receive rename-to -
  91.   \fstripx(\v(filename))_\v(ndate)_\flpad(\v(ntime),5,0)_\v(pid).-
  92.   \flop(\v(filename))
  93.  
  94. which you would execute before putting the Kermit into receive or server
  95. mode.  With this command in effect, a file called ABCD1234.FIL might be
  96. received as ABCD1234_20040721_04739_632.FIL.  Your SET FILE COLLISION
  97. setting should be irrelevant because you won't have any collisions.
  98.  
  99. If you also want to move the file to a different directory at the same
  100. time you rename it, you can include that in the string, e.g.:
  101.  
  102.   set receive rename-to ../Ready/\fstripx(\v(filename))_\v(ndate)-
  103.   _\flpad(\v(ntime),5,0)_\v(pid).\flop(\v(filename))
  104.  
  105. - Frank